/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller.admin;

import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import model.*;

/**
 *
 * @author Administrator
 */
@ManagedBean(name = "dmb")
@SessionScoped
public class DepartmentManagedBean {
    @EJB
    private DepartmentFacade departmentFacade;
    private Department department =new Department();
private String message = new String();

    public String getMessage() {
        return message;
    }

    public void setDepartmentFacade(DepartmentFacade departmentFacade) {
        this.departmentFacade = departmentFacade;
    }

    public Department getDepartment() {
        return department;
    }

    public void setDepartment(Department department) {
        this.department = department;
    }

public DepartmentManagedBean() {
    }
  


    public String adddepart(){
        this.departmentFacade.create(department);
        return "List";
    }
    public String editdepart(){
        this.departmentFacade.edit(department);
        return "List";
    }
    public String deletedepart(){
        String page ="";
        try {
            this.departmentFacade.remove(department);
            page="List";
        } catch (Exception e) {
            this.message ="Delete not found";
        }
        
        return page;
    }
    public List<Department> depList(){
        return this.departmentFacade.findAll();
    }
    public String depEdit(Department dep){
        this.department = dep;
        return "Edit";
    }
    public String depView(Department dep){
        this.department = dep;
        return "View";
    }
}
